<?php
/**
 * Class Controller untuk Aktivitas Genset
 * 
 * @category Application
 * @package Application_Model
 * @filesource Application/Model/Aktivitasharian.php
 * @author Bayu Santoso
 * @copyright 2012 Gede Technology IT Consulting
 */
class Application_Model_Aktivitasharian extends Zend_Db_Table_Abstract
{
    /**
     * Nama Tabel di Database yang digunakan untuk menyimpan data Aktivitas
     * Harian dari Genset-genset yang dimiliki perusahaan
     * 
     * @var string 
     */
    protected $_name = 'tabel_aktivitas_harian';
    
    /**
     * Memasukkan data pemeriksaan aktivitas terbaru dari genset
     * 
     * @param array $data
     * @return array
     */
    public function aktivitasBaru($data)
    {
        $id = $this->insert($data);
        return $id;
    }
    
    public function getDataJoin()
    {
        $select = $this->select();
        $select->from($this->_name)
               ->setIntegrityCheck(false)
               ->joinLeft('tabel_genset', 'tabel_genset.id_genset = tabel_aktivitas_harian.id_genset');
        $result = $this->fetchAll($select);
        return $result->toArray();
    }
    
    public function getDataJoinbyId($id)
    {
        $select = $this->select();
        
        $select->from($this->_name)
               ->setIntegrityCheck(false)
               ->where('id_aktivitas_harian = ?', $id)
               ->joinLeft('tabel_genset', 'tabel_genset.id_genset = tabel_aktivitas_harian.id_genset')
               ->joinLeft('tabel_hasil_pemeriksaan', 'tabel_hasil_pemeriksaan.id_hasil_pemeriksaan = tabel_aktivitas_harian.id_hasil_pemeriksaan')
               ->joinLeft('tabel_waktu_pemeriksaan', 'tabel_waktu_pemeriksaan.id_waktu_pemeriksaan = tabel_aktivitas_harian.id_waktu_pemeriksaan');
        
        $result = $this->fetchRow($select);
        return $result->toArray();
    }
    
    public function getDataJoinbyTgl($tgl)
    {
        $select = $this->select();
        
        $select->from($this->_name)
               ->setIntegrityCheck(false)
               ->where('tanggal_aktivitas = ?', $tgl)
               ->joinLeft('tabel_waktu_pemeriksaan', 'tabel_waktu_pemeriksaan.id_waktu_pemeriksaan = tabel_aktivitas_harian.id_waktu_pemeriksaan')
               ->joinLeft('tabel_genset', 'tabel_genset.id_genset = tabel_aktivitas_harian.id_genset')
               ->joinLeft('tabel_user', 'tabel_user.id_user = tabel_aktivitas_harian.id_user');
        
        $result = $this->fetchAll($select);
        return $result->toArray();
    }
    
    public function getDataJoinbyProyek($id_genset)
    {
        $select = $this->select();
        $select->from($this->_name)
               ->setIntegrityCheck(false)
               ->where('tabel_genset.id_genset = ?', $id_genset)
               ->joinLeft('tabel_genset', 'tabel_genset.id_genset = tabel_aktivitas_harian.id_genset');
        $result = $this->fetchAll($select);
        return $result->toArray();
    }
    
    public function getDatabyIdProyek($id_proyek)
    {
        $select = $this->select();
        $select->from($this->_name)
               ->setIntegrityCheck(false)
               ->where('tabel_genset.id_proyek = ?', $id_proyek)
               ->joinLeft('tabel_genset', 'tabel_aktivitas_harian.id_genset = tabel_genset.id_genset');
        
        $result =$this->fetchAll($select);
        
        return $result->toArray();
    }
    
    public function getDatabyIdGenset($id_genset)
    {
        $select = $this->select();
        
        $select->from($this->_name)
               ->setIntegrityCheck(false)
               ->where('tabel_aktivitas_harian.id_genset = ?', $id_genset)
               ->joinLeft('tabel_genset', 'tabel_genset.id_genset = tabel_aktivitas_harian.id_genset');
        
        $result = $this->fetchAll($select);
        return $result->toArray();
    }
}

